#!/bin/bash -vx
# build rpm packages by cross-compiler
# Liu Yang <yang.liu.sn@gmail.com>
# Fu Wei <tekkamanninja@gmail.com>

#about structure of crossbuild dir
SRPM_DIR=${CROSSBUILD_DIR}/srpms_source
BUILD_LOG_DIR=${CROSSBUILD_DIR}/logs
#we can use git to maintain the rootfs, so there maybe a .git
SYSROOT_DIR=${CROSSBUILD_DIR}/sysroot/${DIST_NAME}/${TARGET_ARCH}/rootfs

CROSS_COMPILE=${TOOL_PREFIX}-

if [ -z "${CROSSTOOLS_DIR}" ]; then
	echo "Please setup CROSSTOOLS_DIR in ${TARGET_ARCH}/arch_env.conf"
	exit 1
fi

if [ -z "${CROSS_COMPILE}" ]; then
	echo "Please setup CROSS_COMPILE !!!"
	exit 1
fi

export PATH="${CROSSTOOLS_DIR}/bin:${PATH}"
export AR=${CROSS_COMPILE}ar
export AS=${CROSS_COMPILE}as
export CC=${CROSS_COMPILE}gcc
export CPP=${CROSS_COMPILE}cpp
export CXX=${CROSS_COMPILE}g++
export LD=${CROSS_COMPILE}ld
export NM=${CROSS_COMPILE}nm
export OBJCOPY=${CROSS_COMPILE}objcopy
export OBJDUMP=${CROSS_COMPILE}objdump
export RANLIB=${CROSS_COMPILE}ranlib
export STRIP=${CROSS_COMPILE}strip
#export LINK=${CROSS_COMPILE}gcc

#setup HOME for rpmbuild
export HOME=${CROSSBUILD_DIR}

export DIST_ID=".${DIST_NAME}"

#export flags
COMMON_FLAGS=" --sysroot=${SYSROOT_DIR} "
export CFLAGS="${CFLAGS} ${COMMON_FLAGS}"
export CXXFLAGS="${CXXFLAGS} ${COMMON_FLAGS}"
export LDFLAGS="${LDFLAGS} ${COMMON_FLAGS}"

echo "COMMON config imported!"
